import unittest,time
from selenium import webdriver
from selenium.webdriver.common.by import By


class Jiuxianw(unittest.TestCase):
    def setUp(self) -> None:
        self.driver=webdriver.Edge()
        self.driver.maximize_window()
        self.driver.get('https://www.jiuxian.com/')

    def tearDown(self) -> None:
        time.sleep(3)
        self.driver.quit()

    def test_Jiuxianw_01_login(self):
        # 点击请登录
        self.driver.find_element(By.CSS_SELECTOR,'.headerLogin').click()
        # 断言1  断言文本：账号登录
        dy1=self.driver.find_element(By.XPATH,'//a[@href="javascript:;"]').text
        print(dy1)
        time.sleep(8)
        # 用户名
        self.driver.find_element(By.ID,'userName').send_keys("13103053968")
        # 密码
        self.driver.find_element(By.NAME,'_pwd').send_keys("jiuxianwang123aaa")
        time.sleep(8)
        # 登录按钮
        self.driver.find_element(By.NAME,'bi_Usuallogin').click()
        time.sleep(8)
        # 登录成功 跳转到首页 断言文本 断言jxw862549358
        dy2 = self.driver.find_element(By.XPATH, '/html/body/div[2]/div/div[1]/div/p/span').text
        print(dy2)
        time.sleep(8)

    def test_Jiuxianw_02_search(self):
        self.test_Jiuxianw_01_login()
        # 点击首页
        self.driver.find_element(By.ID,'httpwwwjiuxiancom').click()
        # 首页输入框定位
        self.driver.find_element(By.NAME,'key').send_keys("雪花")
        # 点击搜索按钮
        self.driver.find_element(By.CSS_SELECTOR,'.search-btn').click()
        # 断言 断言文本 断言雪花
        self.driver.find_element(By.XPATH,'/html/body/div[6]/div/div[2]/div[1]/div[2]/a[2]').click()
        time.sleep(5)
        # 点击雪花啤酒图片  第一个图片
        self.driver.find_element(By.XPATH,'/html/body/div[6]/div/div[2]/div[5]/ul/li[1]/div[2]/div[1]/a/img').click()
        # 点击加入购物车
        # self.driver.find_element(By.XPATH,'//*[@id="addToCartForDetail"]').click()
        # time.sleep(5)